//
//  PlayView.m
//  A_program
//
//  Created by 杨利佳 on 15/5/26.
//  Copyright (c) 2015年 BayMax. All rights reserved.
//

#import "PlayView.h"
#import "Singleton.h"
#import <StreamingKit/STKAudioPlayer.h>
#define myWidth self.frame.size.width
#define myHeight self.frame.size.height

@implementation PlayView

- (void)dealloc
{
    [_currentTime release];
    [_songTime release];
    [_slider release];
    [_next release];
    [_last release];
    [_title release];
    [_backImage release];
    [_show release];
    [_start release];
    [_head release];
    [_personName release];
    [_tracks release];
    [_followers release];
    [_personDescribe release];
    [_back release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self initWithView];
    }
    
    return self;
}

- (void)initWithView
{
    // 返回按钮
    self.back = [[UIButton alloc] initWithFrame:CGRectMake(0, 20, myWidth / 8, myHeight / 10)];
    [_back setImage:[UIImage imageNamed:@"back6.png"] forState:UIControlStateNormal];
    [self addSubview:_back];
    [_back release];
    
    // 标题
     self.title = [[UILabel alloc] initWithFrame:CGRectMake(myWidth / 8, 20, myWidth - myWidth / 8, myHeight / 10)];
    _title.font = [UIFont boldSystemFontOfSize:20];
    [self addSubview:_title];
    [_title release];
    
    // 背景图片
    self.backImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 20 + myHeight / 10, myWidth, myHeight * 0.7)];
    [self addSubview:_backImage];
    [_backImage release];
    _backImage.alpha = 0.2;
    
    // 播放图片
    self.show = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, myWidth / 1.5, myWidth / 1.5)];
    _show.layer.cornerRadius = myWidth / 1.5 / 2;
    _show.layer.masksToBounds = YES;
    _show.center = CGPointMake(myWidth / 2, myHeight  / 2.5);
    [self addSubview:_show];
    [_show release];
    
    // 创建slider
    self.slider = [[UISlider alloc] initWithFrame:CGRectMake(myWidth / 6 , myHeight / 6 * 4, myWidth / 6 * 4, myWidth / 6 * 0.5)];
    self.slider.maximumTrackTintColor = [UIColor orangeColor];
    [self addSubview:self.slider];
    [self.slider release];
    [self.slider addTarget:self action:@selector(sliderAction) forControlEvents:UIControlEventValueChanged];

    self.currentTime = [[UILabel alloc] initWithFrame:CGRectMake(myWidth / 6 - 45, myHeight / 6 * 4, 70, 40)];
    self.songTime = [[UILabel alloc] initWithFrame:CGRectMake(self.slider.frame.origin.x + self.slider.frame.size.width + 5, myHeight / 6 * 4, 70, 40)];
    [self addSubview:_currentTime];
    [self addSubview:_songTime];
    [_currentTime release];
    [_songTime release];

    
    // 播放按钮
    self.start = [[UIButton alloc] initWithFrame:CGRectMake(myWidth / 2 - 15, myHeight / 5 * 3.8, 35, 35)];
    [self addSubview:_start];
    [_start release];
    
    // 上一首按钮
    self.last = [[UIButton alloc] initWithFrame:CGRectMake(20, myHeight / 5 * 3.8, 30, 30)];
    [_last setImage:[UIImage imageNamed:@"befor.png"] forState:UIControlStateNormal];
    [self addSubview:_last];
    [_last release];
    
    // 下一首按钮
    self.next = [[UIButton alloc] initWithFrame:CGRectMake(myWidth - 50, myHeight / 5 * 3.8, 30, 30)];
    [_next setImage:[UIImage imageNamed:@"forward_next.png"] forState:UIControlStateNormal];
    [self addSubview:_next];
    [_next release];
    
    // 主播头像
    self.head = [[UIImageView alloc] initWithFrame:CGRectMake(10, _next.frame.origin.y + 50, 60, myHeight / 9)];
    _head.layer.cornerRadius = 25;
    _head.layer.masksToBounds = YES;
    [self addSubview:_head];
    [_head release];
    
    // 主播名字
    self.personName = [[UILabel alloc] initWithFrame:CGRectMake(80, _next.frame.origin.y + 50, myWidth - 80 , 20)];
    [self addSubview:_personName];
    [_personName release];
    
    // 播放的路径数
    self.tracks = [[UILabel alloc] initWithFrame:CGRectMake(80, _next.frame.origin.y + 75, 100, 20)];
    _tracks.font = [UIFont boldSystemFontOfSize:13];
    _tracks.textColor = [UIColor grayColor];
    [self addSubview:_tracks];
    [_tracks release];
    
    // 粉丝数
    self.followers = [[UILabel alloc] initWithFrame:CGRectMake(190, _next.frame.origin.y + 75, 100, 20)];
    _followers.font = [UIFont boldSystemFontOfSize:13];
    _followers.textColor = [UIColor grayColor];
    [self addSubview:_followers];
    [_followers release];
    
    // 主播描述
     self.personDescribe= [[UILabel alloc] initWithFrame:CGRectMake(75, _followers.frame.origin.y + 20, myWidth - 80, 20)];
    [self addSubview:_personDescribe];
    [_personDescribe release];
    
}

- (void)sliderAction
{
    Singleton *singer = [Singleton shareManager];
    [singer.streamer seekToTime:self.slider.value * singer.streamer.duration];
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
